import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class 只出现一次的数字 {
    public static void main(String[] args) throws IOException {
       // int n = 11; // 确保n为奇数
        int n = 0;
        for (int i = 6; i <= 9; i++) {
            Random random = new Random();
            n = random.nextInt(100000);
            if(n % 2 == 0)n++;
            int[] numbers = generateRandomNumbers(n); // 生成包含一个只出现一次的数字的随机数据
            int uniqueNumber = findUniqueNumber(numbers);

            try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("t" + i + ".in"));
                 BufferedWriter bufferedWriter2 = new BufferedWriter(new FileWriter("t" + i + ".out"))) {
                bufferedWriter.write(n + "\n");
                // 写入输入数据到文件
                for (int num : numbers) {
                    bufferedWriter.write(num + " ");
                }

                // 写入只出现一次的数字到文件
                bufferedWriter2.write(uniqueNumber + " ");
            }
        }
    }

    // 生成随机数据，其中一个数字只出现一次，其余成对出现
    private static int[] generateRandomNumbers(int n) {
        Random random = new Random();
        List<Integer> list = new ArrayList<>();

        // 生成成对出现的数字
        for (int i = 0; i < n/2; i++) {
            int num = random.nextInt(100000);
            list.add(num);
            list.add(num);
        }

        // 生成只出现一次的数字
        int uniqueNumber = random.nextInt(100000);
        list.add(uniqueNumber);

        // 打乱顺序
        Collections.shuffle(list);

        // 转换为数组
        int[] numbers = list.stream().mapToInt(Integer::intValue).toArray();

        return numbers;
    }

    // 找出只出现一次的数字
    private static int findUniqueNumber(int[] numbers) {
        int result = 0;
        for (int num : numbers) {
            result ^= num;
        }
        return result;
    }
}
